from __future__ import division
import numpy as np
from Constant_Physics import Physics
import src_fortran.froutines as fr
from Tools import *
from inspect import stack #To "automatize the clk functions"

class Silicon(Physics):

    def __init__(self,clk,fortran_compiled=True):
        #----------------- source: http://www.ioffe.rssi.ru/SVA/NSM/Semicond/Si/electric.html
        self.fortran_compiled_functions=fortran_compiled
        self.clk=clk
        self.mue = 1400 # cm^2.V^-1.s^-1   electron mobility
        self.muh = 450 # cm^2.V^-1.s^-1   hole mobility
        self.PRCge = 2.005
        self.espin = 1 / 2  #Electronic spin
        self.dim_PRC=2
        self.Sx = np.array([[0, 1], [ 1, 0]])
        self.Sy = np.array([[0, -1j], [1j, 0]])
        self.Sz = np.array([[1, 0], [0, -1]])
        self.S = [self.Sx, self.Sy, self.Sz]
        self.Sd = np.diag([1, 1])
        self.PRCSpinUp = np.array([[1, 0], [0, 0]])
        self.PRCSpinDown = np.array([[0, 0], [0, 1]])
        self.we=Physics.EnergyUnit * self.PRCge * Physics.mue

    def PRC_Hamiltonian_Ze(self, b):
        """
        Input:
            -B: the magnetic field [Bx,By,Bz]
        Output:
            -hamiltonian: the PRC's hamiltonian (here only Zeeman contribution)
        """
        if self.fortran_compiled_functions==True:
            return fr.sptv(self.dim_PRC,self.Sx,self.Sy,self.Sz,b,self.we)    #Ze term
        else:
            return self.we*(self.Sx*b[0]+self.Sy*b[1]+self.Sz*b[2])

